import {
  libraryCategoryTreeByParentId,
  libraryCategoryTreeById,
  libraryCategorySelect,
  libraryCategoryInsert,
  libraryCategoryUpdateById,
  libraryCategoryDelete
} from '@/api/libraryManage/libraryCategoryInfo'

import {
  libraryDocQueryMyDoc,
  libraryDocQueryAllDoc,
  libraryDocQuerybyCategory,
  libraryDocUpload,
  libraryDocDelete,
  libraryDocDeleteBatch,
  libraryDocUpdateDocById,
  libraryDocConvertToPDF
} from '@/api/libraryManage/LibraryDocInfo'

const libraryManage = {
  actions: {
    // 获取文档分类树形结构（通过父ID）
    LibraryCategoryTreeByParentId({ commit }, args) {
      return new Promise((resolve, reject) => {
        libraryCategoryTreeByParentId(args).then(response => {
          resolve(response.data)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 获取文档分类树形结构（通过ID）
    LibraryCategoryTreeById({ commit }, args) {
      return new Promise((resolve, reject) => {
        libraryCategoryTreeById(args).then(response => {
          resolve(response.data)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 查询文档分类
    LibraryCategorySelect({ commit }, args) {
      return new Promise((resolve, reject) => {
        libraryCategorySelect(args).then(response => {
          resolve(response.data)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 插入文档分类
    LibraryCategoryInsert({ commit }, args) {
      return new Promise((resolve, reject) => {
        libraryCategoryInsert(args).then(response => {
          resolve(response.data)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 更新文档分类（通过主键ID）
    LibraryCategoryUpdateById({ commit }, args) {
      return new Promise((resolve, reject) => {
        libraryCategoryUpdateById(args).then(response => {
          resolve(response.data)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 删除文档分类（通过主键ID）
    LibraryCategoryDelete({ commit }, args) {
      return new Promise((resolve, reject) => {
        libraryCategoryDelete(args).then(response => {
          resolve(response.data)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 查询我的文档
    LibraryDocQueryMyDoc({ commit }, args) {
      return new Promise((resolve, reject) => {
        libraryDocQueryMyDoc(args).then(response => {
          resolve(response.data)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 查询所有文档
    LibraryDocQueryAllDoc({ commit }, args) {
      return new Promise((resolve, reject) => {
        libraryDocQueryAllDoc(args).then(response => {
          resolve(response.data)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 通过分类查询文档
    LibraryDocQuerybyCategory({ commit }, args) {
      return new Promise((resolve, reject) => {
        libraryDocQuerybyCategory(args).then(response => {
          resolve(response.data)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 上传文档
    LibraryDocUpload({ commit }, args) {
      return new Promise((resolve, reject) => {
        libraryDocUpload(args).then(response => {
          resolve(response.data)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 删除文档
    LibraryDocDelete({ commit }, args) {
      return new Promise((resolve, reject) => {
        libraryDocDelete(args).then(response => {
          resolve(response.data)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 批量删除文档
    LibraryDocDeleteBatch({ commit }, args) {
      return new Promise((resolve, reject) => {
        libraryDocDeleteBatch(args).then(response => {
          resolve(response.data)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 更新文档
    LibraryDocUpdateDocById({ commit }, args) {
      return new Promise((resolve, reject) => {
        libraryDocUpdateDocById(args).then(response => {
          resolve(response.data)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 手动转化文档为PDF
    LibraryDocConvertToPDF({ commit }, args) {
      return new Promise((resolve, reject) => {
        libraryDocConvertToPDF(args).then(response => {
          resolve(response.data)
        }).catch(error => {
          reject(error)
        })
      })
    }

  }
}

export default libraryManage
